package options;

import gui.OptionsTest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Optionsfenster zum Allgemeinen
 * 
 * @author Michi
 * 
 */
public class AllgemeinPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3696722333819038571L;
	private JLabel blueInt;
	private JLabel greenInt;
	private JLabel redInt;
	private JSlider sliderRed;
	private JSlider sliderGreen;
	private JSlider sliderBlue;
	private JRadioButton rdbtnLatein;
	private JRadioButton rdbtnEnglisch;
	private JRadioButton rdbtnDeutsch;
	private JLabel dummyLabel1;
	private JPanel colorPanel;
	private String[] windowColorsSeperated;
	private JLabel infoPanel1;
	private JLabel dummyLabel2;
	private JLabel dummyLabel_1;
	private JLabel infoPanel0;
	private JLabel dummyLabel3;
	private JLabel dummyLabel3_1;

	// Sprache
	int speak = 0;
	String[] sprache = { "Sprache", "Language", "Linguam" };
	String[] deutsch = { "Deutsch", "German", "German" };
	String[] englisch = { "Englisch", "English", "English" };
	String[] latein = { "Latein", "Latin", "Latinum" };
	String[] h24 = { "24 Stunden", "24h", "24h" };
	String[] format = { "Uhrzeit Format", "Time Format", "Tempore forma" };
	String[] color = { "Programmfarbe", "Organizer Color", "Colorem Progressio" };
	String[] blau = { "Blau:", "Blue:", "Caeruleo:" };
	String[] gruen = { "Gr\u00FCn:", "Green:", "Viride" };
	String[] rot = { "Rot:", "Red:", "Rubrum" };

	String[] aenderungen = {
			"\u00C4nderungen werden nach einem Programmneustart \u00FCbernommen.",
			"Changes are applied after a program restart.",
			"Mutationes applicantur satus progressio." };

	/**
	 * Create the panel.
	 */
	public AllgemeinPanel(final OptionsTest optionsTestInstance) {
		speak = Integer.parseInt(optionsTestInstance.getOr().getLanguage());

		String windowColors = optionsTestInstance.getOr().getColorSetting();
		windowColorsSeperated = windowColors.split(",");
		setBackground(new Color(Integer.parseInt(windowColorsSeperated[0]),
				Integer.parseInt(windowColorsSeperated[1]),
				Integer.parseInt(windowColorsSeperated[2])));
		setMinimumSize(new Dimension(600, 700));
		setMaximumSize(new Dimension(600, 700));
		setPreferredSize(new Dimension(600, 700));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
				0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
				0.0, Double.MIN_VALUE };
		setLayout(gridBagLayout);

		JLabel labelSprache = new JLabel(sprache[speak]);
		labelSprache.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_labelSprache = new GridBagConstraints();
		gbc_labelSprache.anchor = GridBagConstraints.WEST;
		gbc_labelSprache.insets = new Insets(0, 0, 5, 5);
		gbc_labelSprache.gridx = 1;
		gbc_labelSprache.gridy = 1;
		add(labelSprache, gbc_labelSprache);

		rdbtnDeutsch = new JRadioButton(deutsch[speak]);
		rdbtnDeutsch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnDeutsch.setSelected(true);
				rdbtnEnglisch.setSelected(false);
				rdbtnLatein.setSelected(false);
				optionsTestInstance.setLanguage("0");
				infoPanel0.setVisible(true);

			}
		});
		GridBagConstraints gbc_rdbtnDeutsch = new GridBagConstraints();
		gbc_rdbtnDeutsch.anchor = GridBagConstraints.WEST;
		gbc_rdbtnDeutsch.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnDeutsch.gridx = 2;
		gbc_rdbtnDeutsch.gridy = 3;
		add(rdbtnDeutsch, gbc_rdbtnDeutsch);

		rdbtnEnglisch = new JRadioButton(englisch[speak]);
		rdbtnEnglisch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnDeutsch.setSelected(false);
				rdbtnEnglisch.setSelected(true);
				rdbtnLatein.setSelected(false);
				optionsTestInstance.setLanguage("1");
				infoPanel0.setVisible(true);
			}
		});
		GridBagConstraints gbc_rdbtnEnglisch = new GridBagConstraints();
		gbc_rdbtnEnglisch.anchor = GridBagConstraints.WEST;
		gbc_rdbtnEnglisch.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnEnglisch.gridx = 4;
		gbc_rdbtnEnglisch.gridy = 3;
		add(rdbtnEnglisch, gbc_rdbtnEnglisch);

		rdbtnLatein = new JRadioButton(latein[speak]);
		rdbtnLatein.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rdbtnDeutsch.setSelected(false);
				rdbtnEnglisch.setSelected(false);
				rdbtnLatein.setSelected(true);
				optionsTestInstance.setLanguage("2");
				infoPanel0.setVisible(true);
			}
		});
		GridBagConstraints gbc_rdbtnLatein = new GridBagConstraints();
		gbc_rdbtnLatein.anchor = GridBagConstraints.WEST;
		gbc_rdbtnLatein.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnLatein.gridx = 6;
		gbc_rdbtnLatein.gridy = 3;
		add(rdbtnLatein, gbc_rdbtnLatein);

		infoPanel0 = new JLabel(aenderungen[speak]);
		infoPanel0.setVisible(false);
		GridBagConstraints gbc_infoPanel0 = new GridBagConstraints();
		gbc_infoPanel0.anchor = GridBagConstraints.WEST;
		gbc_infoPanel0.gridwidth = 6;
		gbc_infoPanel0.insets = new Insets(0, 0, 5, 5);
		gbc_infoPanel0.gridx = 1;
		gbc_infoPanel0.gridy = 5;
		add(infoPanel0, gbc_infoPanel0);

		dummyLabel3 = new JLabel("   ");
		dummyLabel3.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel3 = new GridBagConstraints();
		gbc_dummyLabel3.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel3.gridx = 1;
		gbc_dummyLabel3.gridy = 6;
		add(dummyLabel3, gbc_dummyLabel3);

		JLabel labelFarbe = new JLabel(color[speak]);
		labelFarbe.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_labelFarbe = new GridBagConstraints();
		gbc_labelFarbe.anchor = GridBagConstraints.WEST;
		gbc_labelFarbe.insets = new Insets(0, 0, 5, 5);
		gbc_labelFarbe.gridx = 1;
		gbc_labelFarbe.gridy = 7;
		add(labelFarbe, gbc_labelFarbe);

		dummyLabel_1 = new JLabel("   ");
		dummyLabel_1.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel_1 = new GridBagConstraints();
		gbc_dummyLabel_1.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel_1.gridx = 1;
		gbc_dummyLabel_1.gridy = 8;
		add(dummyLabel_1, gbc_dummyLabel_1);

		JLabel lblRot = new JLabel(rot[speak]);
		lblRot.setHorizontalTextPosition(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblRot = new GridBagConstraints();
		gbc_lblRot.anchor = GridBagConstraints.EAST;
		gbc_lblRot.insets = new Insets(0, 0, 5, 5);
		gbc_lblRot.gridx = 1;
		gbc_lblRot.gridy = 9;
		add(lblRot, gbc_lblRot);

		sliderRed = new JSlider();
		sliderRed.setMinimum(0);
		sliderRed.setMaximum(255);
		sliderRed.setValue(Integer.parseInt(windowColorsSeperated[0]));
		GridBagConstraints gbc_sliderRed = new GridBagConstraints();
		gbc_sliderRed.gridwidth = 3;
		gbc_sliderRed.insets = new Insets(0, 0, 5, 5);
		gbc_sliderRed.gridx = 2;
		gbc_sliderRed.gridy = 9;
		add(sliderRed, gbc_sliderRed);

		sliderRed.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {

				getRedInt().setText(sliderRed.getValue() + "");
				optionsTestInstance.setColorSetting(sliderRed.getValue() + ","
						+ sliderGreen.getValue() + "," + sliderBlue.getValue());
				renewJLabel(sliderRed.getValue(), sliderGreen.getValue(),
						sliderBlue.getValue());
				infoPanel1.setVisible(true);

			}
		});

		redInt = new JLabel(windowColorsSeperated[0]);
		GridBagConstraints gbc_redInt = new GridBagConstraints();
		gbc_redInt.insets = new Insets(0, 0, 5, 5);
		gbc_redInt.gridx = 6;
		gbc_redInt.gridy = 9;
		add(redInt, gbc_redInt);

		colorPanel = new JPanel();
		colorPanel.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		colorPanel.setBackground(new Color(Integer
				.parseInt(windowColorsSeperated[0]), Integer
				.parseInt(windowColorsSeperated[1]), Integer
				.parseInt(windowColorsSeperated[2])));
		colorPanel.setMaximumSize(new Dimension(87, 87));
		colorPanel.setMinimumSize(new Dimension(87, 87));
		colorPanel.setPreferredSize(new Dimension(87, 87));
		GridBagConstraints gbc_colorLabel = new GridBagConstraints();
		gbc_colorLabel.gridheight = 3;
		gbc_colorLabel.insets = new Insets(0, 0, 5, 0);
		gbc_colorLabel.gridx = 8;
		gbc_colorLabel.gridy = 9;
		add(colorPanel, gbc_colorLabel);

		JLabel lblGrn = new JLabel(gruen[speak]);
		GridBagConstraints gbc_lblGrn = new GridBagConstraints();
		gbc_lblGrn.anchor = GridBagConstraints.EAST;
		gbc_lblGrn.insets = new Insets(0, 0, 5, 5);
		gbc_lblGrn.gridx = 1;
		gbc_lblGrn.gridy = 10;
		add(lblGrn, gbc_lblGrn);

		sliderGreen = new JSlider();
		sliderGreen.setMinimum(0);
		sliderGreen.setMaximum(255);
		sliderGreen.setValue(Integer.parseInt(windowColorsSeperated[1]));
		GridBagConstraints gbc_sliderGreen = new GridBagConstraints();
		gbc_sliderGreen.gridwidth = 3;
		gbc_sliderGreen.insets = new Insets(0, 0, 5, 5);
		gbc_sliderGreen.gridx = 2;
		gbc_sliderGreen.gridy = 10;
		add(sliderGreen, gbc_sliderGreen);
		sliderGreen.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				getGreenInt().setText(sliderGreen.getValue() + "");
				optionsTestInstance.setColorSetting(sliderRed.getValue() + ","
						+ sliderGreen.getValue() + "," + sliderBlue.getValue());
				renewJLabel(sliderRed.getValue(), sliderGreen.getValue(),
						sliderBlue.getValue());
				infoPanel1.setVisible(true);
			}
		});

		greenInt = new JLabel(windowColorsSeperated[1]);
		GridBagConstraints gbc_greenInt = new GridBagConstraints();
		gbc_greenInt.insets = new Insets(0, 0, 5, 5);
		gbc_greenInt.gridx = 6;
		gbc_greenInt.gridy = 10;
		add(greenInt, gbc_greenInt);

		JLabel lblBlau = new JLabel(blau[speak]);
		lblBlau.setHorizontalAlignment(SwingConstants.RIGHT);
		GridBagConstraints gbc_lblBlau = new GridBagConstraints();
		gbc_lblBlau.anchor = GridBagConstraints.EAST;
		gbc_lblBlau.insets = new Insets(0, 0, 5, 5);
		gbc_lblBlau.gridx = 1;
		gbc_lblBlau.gridy = 11;
		add(lblBlau, gbc_lblBlau);

		sliderBlue = new JSlider();
		sliderBlue.setMinimum(0);
		sliderBlue.setMaximum(255);
		sliderBlue.setValue(Integer.parseInt(windowColorsSeperated[2]));
		GridBagConstraints gbc_sliderBlue = new GridBagConstraints();
		gbc_sliderBlue.gridwidth = 3;
		gbc_sliderBlue.insets = new Insets(0, 0, 5, 5);
		gbc_sliderBlue.gridx = 2;
		gbc_sliderBlue.gridy = 11;
		add(sliderBlue, gbc_sliderBlue);

		sliderBlue.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				getBlueInt().setText(sliderBlue.getValue() + "");
				optionsTestInstance.setColorSetting(sliderRed.getValue() + ","
						+ sliderGreen.getValue() + "," + sliderBlue.getValue());
				renewJLabel(sliderRed.getValue(), sliderGreen.getValue(),
						sliderBlue.getValue());
				infoPanel1.setVisible(true);

			}
		});

		blueInt = new JLabel(windowColorsSeperated[2]);
		GridBagConstraints gbc_blueInt = new GridBagConstraints();
		gbc_blueInt.insets = new Insets(0, 0, 5, 5);
		gbc_blueInt.gridx = 6;
		gbc_blueInt.gridy = 11;
		add(blueInt, gbc_blueInt);

		dummyLabel1 = new JLabel("   ");
		dummyLabel1.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel1 = new GridBagConstraints();
		gbc_dummyLabel1.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel1.gridx = 1;
		gbc_dummyLabel1.gridy = 12;
		add(dummyLabel1, gbc_dummyLabel1);

		infoPanel1 = new JLabel(aenderungen[speak]);

		infoPanel1.setVisible(false);
		GridBagConstraints gbc_infoPanel1 = new GridBagConstraints();
		gbc_infoPanel1.gridwidth = 8;
		gbc_infoPanel1.anchor = GridBagConstraints.WEST;
		gbc_infoPanel1.insets = new Insets(0, 0, 5, 0);
		gbc_infoPanel1.gridx = 1;
		gbc_infoPanel1.gridy = 13;
		add(infoPanel1, gbc_infoPanel1);

		dummyLabel2 = new JLabel("  ");
		dummyLabel2.setPreferredSize(new Dimension(8, 25));
		GridBagConstraints gbc_dummyLabel2 = new GridBagConstraints();
		gbc_dummyLabel2.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel2.gridx = 1;
		gbc_dummyLabel2.gridy = 14;
		add(dummyLabel2, gbc_dummyLabel2);

		dummyLabel3_1 = new JLabel("   ");
		dummyLabel3_1.setPreferredSize(new Dimension(12, 25));
		GridBagConstraints gbc_dummyLabel3_1 = new GridBagConstraints();
		gbc_dummyLabel3_1.insets = new Insets(0, 0, 5, 5);
		gbc_dummyLabel3_1.gridx = 1;
		gbc_dummyLabel3_1.gridy = 17;
		add(dummyLabel3_1, gbc_dummyLabel3_1);

		if (optionsTestInstance.getLanguage().equals("0")) {
			rdbtnDeutsch.setSelected(true);
		} else if (optionsTestInstance.getLanguage().equals("1")) {
			rdbtnEnglisch.setSelected(true);
		} else if (optionsTestInstance.getLanguage().equals("2")) {
			rdbtnLatein.setSelected(true);
		}

		else {
			rdbtnDeutsch.setSelected(true);
		}

	}

	public void renewJLabel(int r, int g, int b) {
		remove(colorPanel);
		colorPanel = new JPanel();
		colorPanel.setBorder(BorderFactory.createLineBorder(Color.black, 2));
		colorPanel.setBackground(new Color(r, g, b));
		colorPanel.setMaximumSize(new Dimension(87, 87));
		colorPanel.setMinimumSize(new Dimension(87, 87));
		colorPanel.setPreferredSize(new Dimension(87, 87));
		GridBagConstraints gbc_colorLabel = new GridBagConstraints();
		gbc_colorLabel.gridheight = 3;
		gbc_colorLabel.insets = new Insets(0, 0, 5, 0);
		gbc_colorLabel.gridx = 8;
		gbc_colorLabel.gridy = 9;
		add(colorPanel, gbc_colorLabel);

	}

	public void forceRepaint() {
		paint(getGraphics());
	}

	public JLabel getBlueInt() {
		return blueInt;
	}

	public void setBlueInt(JLabel blueInt) {
		this.blueInt = blueInt;
	}

	public JLabel getGreenInt() {
		return greenInt;
	}

	public void setGreenInt(JLabel greenInt) {
		this.greenInt = greenInt;
	}

	public JLabel getRedInt() {
		return redInt;
	}

	public void setRedInt(JLabel redInt) {
		this.redInt = redInt;
	}

	public JSlider getSliderRed() {
		return sliderRed;
	}

	public void setSliderRed(JSlider sliderRed) {
		this.sliderRed = sliderRed;
	}

	public JSlider getSliderGreen() {
		return sliderGreen;
	}

	public void setSliderGreen(JSlider sliderGreen) {
		this.sliderGreen = sliderGreen;
	}

	public JSlider getSliderBlue() {
		return sliderBlue;
	}

	public void setSliderBlue(JSlider sliderBlue) {
		this.sliderBlue = sliderBlue;
	}

	public JRadioButton getRdbtnLatein() {
		return rdbtnLatein;
	}

	public void setRdbtnLatein(JRadioButton rdbtnLatein) {
		this.rdbtnLatein = rdbtnLatein;
	}

	public JRadioButton getRdbtnEnglisch() {
		return rdbtnEnglisch;
	}

	public void setRdbtnEnglisch(JRadioButton rdbtnEnglisch) {
		this.rdbtnEnglisch = rdbtnEnglisch;
	}

	public JRadioButton getRdbtnDeutsch() {
		return rdbtnDeutsch;
	}

	public void setRdbtnDeutsch(JRadioButton rdbtnDeutsch) {
		this.rdbtnDeutsch = rdbtnDeutsch;
	}

}
